<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1400px">
        <el-table  v-loading="loading" :data="tableData" border script>
            <el-table-column label="ID" prop="id" min-width="60"> </el-table-column>
            <el-table-column label="图片" min-width="100">
                <template slot-scope="scope">
                    <ImageUploadImg v-model="scope.row.image_url" :readOnly="true"></ImageUploadImg>
                </template>
            </el-table-column>
            <el-table-column label="seller_sku" prop="sku" min-width="200"></el-table-column>
            <!-- <el-table-column label="平台SKU" prop="platform_sku" min-width="200"></el-table-column> -->
            <el-table-column label="价格" prop="price" min-width="200"></el-table-column>
            <el-table-column label="库存" prop="inventory_num" min-width="200"></el-table-column>
            <el-table-column label="重量" prop="weight" min-width="200"></el-table-column>
            <!-- <el-table-column label="操作" width="100"> -->
                <!-- <template slot-scope="scope"> -->
                    <!-- <el-button type="text" icon="el-icon-edit" @click="showSkuEditDialog(scope.row)">编辑</el-button> -->
                <!-- </template> -->
            <!-- </el-table-column> -->
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList" />
        <div slot="footer" class="dialog-footer"></div>

        <sku-edit-dialog v-model="skuEditDialog.visible" v-if="skuEditDialog.visible" :params="skuEditDialog.data" @success="handleQuery"></sku-edit-dialog>
    </el-dialog>
</template>

<script>
import { shopSpuList } from '@/api/listing'
import SkuEditDialog from './skuEditDialog.vue'
export default {
    name: 'spuListDialog',
    components: { SkuEditDialog },
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            loading: false,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            pageInfo: {
                page: 1,
                limit: 10,
            },
            skuEditDialog: {
                visible: false,
                data: {},
            },
        }
    },
    computed: {
        title() {
            return `SKU列表`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    watch: {
        params: {
            handler(val) {
                if (val.id) {
                    this.getList()
                }
            },
            immediate: true,
            deep: true,
        },
    },
    created() {},
    methods: {
        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
        showSkuEditDialog(row) {
            this.skuEditDialog.visible = true
            this.skuEditDialog.data = row
        },
        getList() {
            
            this.loading = true
            shopSpuList({id: this.params.id,shop_id: this.params.shop_id, limit: this.pageInfo.limit, page: this.pageInfo.page})
                .then(res => {
                    this.tableData = res.data?.list ?? []
                    this.total = res.data?.total ?? 0
                })
                .finally(() => {
                    this.loading = false
                })
        },
    },
}
</script>

<style></style>
